<!--
 * @Description: 
 * @Author: wanghongjian
 * @@github: https://github.com/whj0117
 * @Date: 2025-11-06 17:16:47
 * @LastEditors: wanghongjian
 * @LastEditTime: 2025-11-30 17:34:46
-->
<template>
  <div class="app-container">
    <div class="left-content">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="未审核" name="first">
          <el-empty v-show="!unreviewedList.length" description="暂无数据"></el-empty>
          <div class="info-content" v-show="unreviewedList.length">
            <div class="info-item" :class="{ 'active': userId === item.userId }" v-for="item in unreviewedList"
              :key="item.userId" @click="handleItem(item.userId)">
              <div class="item-left">
                <img :src="item.headPicture" alt="" />
                <div class="l-info">
                  <div class="username">{{ item.wxName }}</div>
                  <div>{{ item.realName }}</div>
                </div>
              </div>
              <div class="item-right">
                <div class="time">{{ item.examineTime }}</div>
                <div>{{ item.addressDistrictName }}</div>
              </div>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="已走访" name="second">
          <el-empty v-show="!reviewedList.length" description="暂无数据"></el-empty>
          <div class="info-content" v-show="reviewedList.length">
            <div class="info-item" :class="{ 'active': userId === item.userId }" v-for="item in reviewedList"
              :key="item.userId" @click="handleItem(item.userId)">
              <div class="item-left">
                <img :src="item.headPicture" alt="" />
                <div class="l-info">
                  <div class="username">{{ item.wxName }}</div>
                  <div>{{ item.realName }}</div>
                </div>
              </div>
              <div class="item-right">
                <div class="time">{{ item.visitTime }}</div>
                <div>{{ item.addressDistrictName }}</div>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="right-content" v-show="!userId">
      <el-empty description="暂无数据"></el-empty>
    </div>
    <div class="right-content" v-show="userId">
      <div class="tags-item">
        <div class="tags-item-list">
          <div class="list-title">
            <div class="title">个人基本情况</div>
            <div class="line"></div>
          </div>
          <div class="list-content">
            <div class="list-content-item">
              <div>
                <div class="title">昵称</div>
                <div class="content">{{ userDetail.wxName }}</div>
              </div>
              <div>
                <div class="title">姓名</div>
                <div class="content">{{ userDetail.realName }}</div>
              </div>
            </div>
            <div class="list-content-item">
              <div>
                <div class="title">性别</div>
                <div class="content">
                  <span v-if="!isEdit">{{ getCommonData('sex', userDetail.sex) }}</span>
                  <el-select v-else v-model="userDetail.sex" clearable placeholder="请选择">
                    <el-option v-for="item in commonData.sex" :key="item.key" :label="item.val"
                      :value="item.key"></el-option>
                  </el-select>
                </div>
              </div>
              <div>
                <div class="title">出生</div>
                <div class="content">{{ userDetail.birthday }}年</div>
              </div>
            </div>
            <div class="list-content-item">
              <div>
                <div class="title">身高</div>
                <div class="content">{{ userDetail.height }}cm</div>
              </div>
              <div>
                <div class="title">体重</div>
                <div class="content">{{ userDetail.weight }}kg</div>
              </div>
            </div>
            <div class="list-content-item">
              <div>
                <div class="title">民族</div>
                <div class="content">{{ userDetail.nationality }}族</div>
              </div>
              <div>
                <div class="title">学历</div>
                <div class="content">{{ getCommonData('education', userDetail.educational) }}</div>
              </div>
            </div>
            <div class="list-content-item">
              <div>
                <div class="title">居住地</div>
                <div class="content">{{ userDetail.addressCityName }}{{ userDetail.addressDistrictName }}</div>
              </div>
              <div>
                <div class="title">婚姻</div>
                <div class="content">{{ getCommonData('marryStatus', userDetail.marry) }}</div>
              </div>
            </div>
            <div class="list-content-item">
              <div>
                <div class="title">购房情况</div>
                <div class="content">{{ getCommonData('buyHouse', userDetail.buyHouse) }}</div>
              </div>
              <div>
                <div class="title">购车情况</div>
                <div class="content">{{ getCommonData('buyCar', userDetail.buyCar) }}</div>
              </div>
            </div>
            <div class="list-content-item">
              <div>
                <div class="title">公司性质</div>
                <div class="content">{{ getCommonData('companyProperty', userDetail.companyProperty) }}</div>
              </div>
              <div>
                <div class="title">职业</div>
                <div class="content">{{ userDetail.workName }}</div>
              </div>
            </div>
            <div class="list-content-item">
              <div>
                <div class="title">月收入</div>
                <div class="content">{{ userDetail.income }}千</div>
              </div>
              <div>
                <div class="title">是否吸烟</div>
                <div class="content">{{ getCommonData('isSmoke', userDetail.isSmoke) }}</div>
              </div>
            </div>
            <div class="list-content-item">
              <div>
                <div class="title">是否喝酒</div>
                <div class="content">{{ getCommonData('isDrink', userDetail.isDrink) }}</div>
              </div>
              <div>
                <div class="title">有没有孩子</div>
                <div class="content">{{ getCommonData('isChild', userDetail.isChild) }}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="tags-item-list" v-show="activeName === 'second'">
          <div class="list-title">
            <div class="title">信息认证</div>
            <div class="line"></div>
          </div>
          <div class="list-content">
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="实名认证" prop="isRealMark">
                    <el-select v-model="form.isRealMark" placeholder="实名认证" style="width: 100%">
                      <el-option label="已认证" :value="true"></el-option>
                      <el-option label="未认证" :value="false"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="学历认证" prop="isEducationalMark">
                    <el-select v-model="form.isEducationalMark" placeholder="学历认证" style="width: 100%">
                      <el-option label="已认证" :value="true"></el-option>
                      <el-option label="未认证" :value="false"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="房子认证" prop="isHouseMark">
                    <el-select v-model="form.isHouseMark" placeholder="房子认证" style="width: 100%">
                      <el-option label="有" :value="true"></el-option>
                      <el-option label="无" :value="false"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="车子认证" prop="isCarMark">
                    <el-select v-model="form.isCarMark" placeholder="车子认证" style="width: 100%">
                      <el-option label="有" :value="true"></el-option>
                      <el-option label="无" :value="false"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </div>
      </div>
      <div class="btn">
        <el-button v-if="activeName === 'second'" @click="handleVerifyBack" style="
            width: 130px;
            height: 40px;
            border-color: #ffd3eb;
            background-color: #fff;
            color: #ff47ab;
          ">驳回</el-button>
        <el-button v-if="activeName === 'first'" @click="handleVerifyVisit" style="
            width: 130px;
            height: 40px;
            border-color: #ff47ab;
            background-color: #ff47ab;
            color: #fff;
          ">添加到走访</el-button>
        <el-button v-else @click="handleVerifyPass" style="
            width: 130px;
            height: 40px;
            border-color: #ff47ab;
            background-color: #ff47ab;
            color: #fff;
          ">审核通过</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import { verifyExamineList, verifyVisitList, userInfo, verifyVisit, verifyBack, verifyPass } from "@/api/user"
import { getFormData } from '@/utils'
import { mapGetters } from "vuex"

export default {
  name: "Customerforecast",
  components: { Pagination },
  data() {
    return {
      form: {
        isRealMark:null,
        isEducationalMark:null,
        isHouseMark:null,
        isCarMark:null
      },
      rules: {
        isRealMark: [
          { required: true, message: '请选择实名认证', trigger: 'change' }
        ],
        isEducationalMark: [
          { required: true, message: '请选择学历认证', trigger: 'change' }
        ],
        isHouseMark: [
          { required: true, message: '请选择房子认证', trigger: 'change' }
        ],
        isCarMark: [
          { required: true, message: '请选择车子认证', trigger: 'change' }
        ]
      },
      activeName: "first",
      query: {
        pageNumber: 1,
        pageSize: 100000,
      },
      shareDrawer: false,
      detailDrawer: false,
      unreviewedList: [],
      reviewedList: [],
      oIndex: null,
      userDetail: {},
      userArchive: {},
      intention: {},
      userId: null,
    };
  },
  computed: {
    ...mapGetters(['commonData'])
  },
  mounted() {
    this.getInfo();
  },
  methods: {
    handleVerifyPass() {
      this.$refs["form"].validate(async valid => {
        if (valid) {
          await verifyPass(getFormData({ userId: this.userId,...this.form }))
          this.$message.success("审核通过！")
          this.userId = null
          this.getReviewed()
        }
      });
    },
    async handleVerifyBack() {
      await verifyBack(getFormData({ userId: this.userId }))
      this.$message.success("驳回成功！")
      this.userId = null
      this.getReviewed()
    },
    async handleVerifyVisit() {
      await verifyVisit(getFormData({ userId: this.userId }))
      this.$message.success("添加到走访成功！")
      this.userId = null
      this.getInfo()
    },
    getCommonData(key, val) {
      if (val) return this.commonData[key].find(type => type.key == val).val
      return ''
    },
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 9) {
        if (columnIndex === 1) {
          return [1, 3];
        } else if (columnIndex === 1) {
          return [0, 0];
        }
      }
    },
    async getInfo() {
      const { records } = await verifyExamineList(getFormData(this.query))
      this.unreviewedList = records
    },
    async getReviewed() {
      const { records } = await verifyVisitList(getFormData(this.query))
      this.reviewedList = records
    },
    handleShare() {
      this.shareDrawer = true;
    },
    handleClick({ index }) {
      this.userId = null
      if (index == 0) {
        this.getInfo()
      } else {
        this.getReviewed()
      }
    },
    async handleItem(userId) {
      this.userId = userId
      const { userDetail, userArchive, intention } = await userInfo(getFormData({
        userId
      }))
      this.userDetail = userDetail
      this.userArchive = userArchive
      this.intention = intention
    }
  },
};
</script>
<style scoped lang="scss">
.app-container {
  display: flex;
  align-content: center;
  justify-content: space-between;

  .left-content {
    width: 348px;

    /* 修改垂直滚动条 */
    ::-webkit-scrollbar {
      width: 0;
      /* 修改宽度 */
    }

    ::v-deep .el-tabs {
      .el-tabs__header {
        .el-tabs__nav-scroll {
          padding: 0 60px;
          box-sizing: border-box;
        }

        .el-tabs__nav {
          .el-tabs__active-bar {
            background-color: #ff47ab;
          }

          .el-tabs__item {
            padding: 0 50px;
            font-weight: 400;
            font-size: 16px;
            color: #777777;

            &:nth-child(2) {
              padding-left: 0;
            }

            &:last-child {
              padding-right: 0;
            }

            &.is-active {
              font-weight: bold;
              color: #ff47ab;
            }
          }
        }
      }
    }

    .info-content {
      overflow: auto;
      height: calc(100vh - 160px);

      .info-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 10px;
        padding: 10px;
        box-sizing: border-box;
        background-color: #fff;
        border-radius: 4px 4px 4px 4px;
        border: 1px solid transparent;
        cursor: pointer;

        &.active {
          border-color: #ff47ab;
        }

        &:last-child {
          margin-bottom: 0;
        }

        .item-left {
          display: flex;
          align-items: center;
          font-weight: bold;
          font-size: 16px;
          color: #222222;

          img {
            width: 60px;
            height: 60px;
            border-radius: 6px 6px 6px 6px;
          }

          .l-info {
            margin-left: 8px;

            .username {
              margin-bottom: 15px;
              font-size: 14px;
              color: #777777;
            }
          }
        }

        .item-right {
          text-align: right;
          font-size: 14px;
          color: #222222;

          .time {
            margin-bottom: 15px;
          }
        }
      }
    }
  }

  .right-content {
    position: relative;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 100px);
    margin-left: 20px;
    padding-top: 20px;
    box-sizing: border-box;
    background-color: #fff;
    border-radius: 4px 4px 4px 4px;

    .tags-item {
      padding-bottom: 60px;
      box-sizing: border-box;

      .tags-item-list {
        margin-bottom: 60px;
        padding: 0 30px;
        box-sizing: border-box;

        &:last-child {
          margin-bottom: 0;
        }

        .list-title {
          display: flex;
          align-items: center;
          justify-content: space-between;

          .title {
            height: 14px;
            line-height: 14px;
            padding-left: 16px;
            border-left: 4px solid #ff47ab;
            box-sizing: border-box;
            font-weight: bold;
            font-size: 14px;
            color: #222222;
          }

          .line {
            flex: 1;
            margin-left: 20px;
            border-top: 1px dashed #999999;
          }

          .edit {
            font-weight: 400;
            font-size: 14px;
            color: #222222;
            cursor: pointer;
          }
        }

        .list-content {
          margin-top: 30px;

          ::v-deep .tableColumnClassName {
            background-color: #f1f3f7;
          }

          .list-content-item {
            display: flex;
            font-weight: 400;
            font-size: 14px;
            color: #444444;
            border: 1px solid #999999;
            border-bottom: none;

            &:last-child {
              border-bottom: 1px solid #999999;
            }

            &>div {
              flex: 1;
              display: flex;
              height: 40px;

              &>div {
                line-height: 40px;
                padding: 0 10px;
                box-sizing: border-box;
              }
            }

            .title {
              width: 160px;
              text-align: right;
              background-color: #F1F3F7;
            }

            .content {
              flex: 1;
              text-align: left;

              .el-button {
                width: 100%;
              }

              .el-select {
                width: 100%;

                .el-input {
                  width: 100%;
                }
              }
            }
          }

          &.information-authentication {
            display: flex;
            align-items: center;

            .info-item {
              margin-right: 46px;
              font-size: 14px;
              color: #777777;

              &>img {
                width: 50px;
                height: 50px;
                margin-bottom: 12px;
              }
            }
          }

          &.textarea-content {
            line-height: 20px;
            font-size: 14px;
            color: #444444;
          }

          &.interrogate-content {
            .interrogate-item {
              margin-bottom: 30px;
              font-weight: 400;
              font-size: 14px;
              color: #444444;
              line-height: 20px;

              &:last-child {
                margin-bottom: 0;
              }

              .interrogate-title {
                margin-bottom: 16px;
                font-size: 14px;
                color: #ff47ab;
              }

              .interrogate-text {
                padding-left: 20px;
                box-sizing: border-box;
              }
            }
          }
        }
      }

      .filter-wrap {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 20px;

        .filter-container {
          margin-bottom: 0;
        }
      }
    }

    .btn {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      z-index: 99;
      position: absolute;
      bottom: 0;
      width: 100%;
      height: 100px;
      padding: 0 30px;
      box-shadow: 0px -4px 4px 0px rgba(0, 0, 0, 0.08);
      border-radius: 4px 4px 4px 4px;
      background-color: #ffffff;
      box-sizing: border-box;
      text-align: right;
    }
  }
}
</style>